package cn.pupil.demo.design.domain.service.logic;

import cn.pupil.demo.design.domain.model.vo.TreeNodeLink;

import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Author: pupil
 * @Date: 2024/07/25 下午 4:28
 */
public abstract class BaseLogic implements LogicFilter {

    @Override
    public Long filter(String matterValue, List<TreeNodeLink> treeNodeLineInfoList) {
        for (TreeNodeLink treeNodeLink : treeNodeLineInfoList) {
            if (decisionLogic(matterValue,treeNodeLink)) return treeNodeLink.getNodeIdTo();
        }
        return 0L;
    }


    @Override
    public abstract String matterValue(Long treeId, String userId, Map<String, String> decisionMatter);


    /**
     *
     * @param matterValue 决策值
     * @param nodeLink 决策链路
     * @return
     */
    private boolean decisionLogic(String matterValue, TreeNodeLink nodeLink) {
        // 获取策略链路的决策类型
        switch (nodeLink.getRuleLimitType()) {
            case 1:
                return matterValue.equals(nodeLink.getRuleLimitValue()); // 等于
            case 2:
                return Double.parseDouble(matterValue) > Double.parseDouble(nodeLink.getRuleLimitValue()); // 大于
            case 3:
                return Double.parseDouble(matterValue) < Double.parseDouble(nodeLink.getRuleLimitValue()); // 小于
            case 4:
                return Double.parseDouble(matterValue) <= Double.parseDouble(nodeLink.getRuleLimitValue()); // 小于等于
            case 5:
                return Double.parseDouble(matterValue) >= Double.parseDouble(nodeLink.getRuleLimitValue()); // 大于等于
            default:
                return false;
        }
    }

}
